package com.riwon.im.common.result;


/**
 * 此类使用有风险,不建议使用此类进行一些流程的控制,这样易形成不可控的问题.<br>
 * 此异常在在controller层,有默认的处理的逻辑.<br/>
 * 当未对异常做相关处理时,BaseController 会将此异常响应（@ResponseBody的方式）给调用者
 * 参见如下使用场景:
 * <ul>
 * <li>需要在service明确抛出运行时异常时,且controller只需要@ResponseBody的方式返回结果时</li>
 * <li>未完善（讨论补充,或讨论此类的废除,找到更好的解决方案）</li>
 * </ul>
 *
 * @author k.f 2017/06/23
 */
public class CustomIllegalStateException extends IllegalStateException {

  private static final long serialVersionUID = 1L;


  private String message = "";

  private Integer code;

  private String key;

  private ResponseStatus status;


  public String getKey() {
    return key;
  }


  public void setKey(String key) {
    this.key = key;
  }


  public CustomIllegalStateException(String message, Integer code, String key) {
    super(message);
    this.setMessage(message);
    this.setCode(code);
    this.setKey(key);
  }
  
  public CustomIllegalStateException(ResponseStatus status) {
    super(status.statusMsg());
    this.status = status;
    this.setMessage(status.statusMsg());
    this.setCode(status.status());
    this.setKey(status.toString().toLowerCase());
  }

  public CustomIllegalStateException(String message, ResponseStatus status) {
    super(message);
    this.status = status;
    this.setMessage(message);
    this.setCode(status.status());
    this.setKey(status.toString().toLowerCase());
  }

  public CustomIllegalStateException(String message){
    super(message);
    this.status = CommonRespStatus.PARAMETER_ERROR;
    this.setMessage(message);
    this.setCode(status.status());
    this.setKey(status.statusDes());
  }

  public String getMessage() {
    return message;
  }


  public void setMessage(String message) {
    this.message = message;
  }


  public Integer getCode() {
    return code;
  }


  public void setCode(Integer code) {
    this.code = code;
  }

  public ResponseStatus getStatus() {
    return status;
  }

  public void setStatus(ResultData.Status status) {
    this.status = status;
  }
}
